import requests
from requests import RequestException


class TodayStudentData:
    def __init__(self):
        self.session = requests.Session()
        # self.base_url = 'http://127.0.0.1:8081'
        self.base_url = 'http://101.200.166.120:8081'

    # 获取当天学员及导师分配情况
    def getTodayStudentData(self):
        url = '/autoMsg/getTodayStudentAndTeacher'
        print(self.base_url + url)
        result = self.session.request('GET', url=f"{self.base_url}{url}", json=None)
        print(result.text)
        if result.status_code == 200 and result.json().get('code') == 200:
            return result.json()['data']
        else:
            raise RequestException('获取当天学员及导师分配情况接口请求失败')

    # 拉群结果回调
    def sendMsg(self, sendData):
        url = '/autoMsg/studentAndTeacherCallBack'
        print(self.base_url + url)
        result = self.session.request('POST', url=f"{self.base_url}{url}", json=sendData)
        print(result.text)
        if result.status_code == 200 and result.json().get('code') == 200:
            return result.json()['data']
        else:
            raise RequestException('拉群结果回调接口请求失败')
